/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年9月4日
 */
package com.massyframework.beanskin.runtime.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.massyframework.beanskin.service.ServiceReference;

/**
 * 实现{@link ServiceReference}
 * @author huangkh
 *
 */
public class DefaultServiceReference<S> implements ServiceReference<S> {

	private final Map<String, Object> props;

	/**
	 * 构造方法
	 */
	public DefaultServiceReference(Map<String, Object> props) {
        this.props = Collections.unmodifiableMap(props);
    }

	/**
     * 按<code>name</code>获取属性
     *
     * @param name {@link String}, 属性名
     * @return {@link Object}, 属性值，属性不存在返回null.
     */
    @Override
    public Object getProperty(String name) {
        if (name == null) return null;
        return this.props.get(name);
    }

    /**
     * 获取所有属性名
     *
     * @return {@link List}, 属性名列表
     */
    @Override
    public List<String> getPropertyNames() {
        return new ArrayList<String>(this.props.keySet());
    }

    /**
     * 服务属性
     * @return {@link Map}
     */
    Map<String, Object> getServiceProperties(){
        return this.props;
    }

    @Override
    public String toString() {
        return "DefaultServiceReference";
    }
}
